import { Column, Entity, ManyToOne, OneToMany, Index } from 'typeorm';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from '../../user/entities/user.entity';
import { UserFavorite } from './user-favorite.entity';

export enum BookshelfStatus {
  DISABLED = 0,
  ACTIVE = 1,
}

@Entity('bookshelves')
@Index(['userId'], { unique: false })
export class Bookshelf extends BaseEntity {
  @Column({ type: 'bigint', comment: '用户ID' })
  userId: number;

  @Column({ type: 'varchar', length: 100, comment: '书架名称' })
  name: string;

  @Column({ type: 'text', nullable: true, comment: '书架描述' })
  description?: string;

  @Column({
    type: 'int',
    default: 0,
    comment: '排序，数字越小越靠前'
  })
  sortOrder: number;

  @Column({
    type: 'tinyint',
    default: 0,
    comment: '是否默认书架: 0-否 1-是'
  })
  isDefault: boolean;

  @Column({
    type: 'tinyint',
    default: BookshelfStatus.ACTIVE,
    comment: '状态: 0-禁用 1-正常',
  })
  status: BookshelfStatus;

  // 关联关系
  @ManyToOne(() => User, (user) => user.bookshelves, { onDelete: 'CASCADE' })
  user: User;

  @OneToMany(() => UserFavorite, (favorite) => favorite.bookshelf)
  favorites: UserFavorite[];
}